/*************************************
 **   @author: 野狼上校               **
 **   @create: 2024-04-03 18:23      **
 **   @version: 1.0                  **
 *************************************/
/**  动态路由 **/

import router from "@/router/index.ts";
import {userStore} from "@/pinia/auth/userPinia.ts";

router.beforeEach((to, from, next) => {
    //白名单
    const whileList = ["/", "/login", "/login/loginInfo", "/login/loginPhone", "/login/getVerify"];

    // 不需要Token就能访问的路径
    if (whileList.includes(to.path)) {
        next();
    } else {  // 需要Token
        if (userStore().token && userStore().token.length > 0) {    // token 存在
            next();
        } else {     // token 不存在
            // 跳到登录页面
            next('/');
        }
    }
});